﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class WaterRipplesForm : ItemFormTemplate
    {
        public WaterRipplesForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\WaterRipplesForm\\WaterRipplesForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();

            if (this.ViewVisible)
            {
                this.demo_control.AnimationEnabled = true;
            }
        }

        public override void ShowView()
        {
            base.ShowView();

            if (this.ViewStatus > ItemFormTemplateStatus.Create && this.ViewStatus < ItemFormTemplateStatus.Closed)
            {
                this.demo_control.AnimationEnabled = true;
            }
        }

        public override void HideView()
        {
            base.HideView();

            this.demo_control.AnimationEnabled = false;
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.StylePattern = WaterRipplesStylePattern.Circle;
            this.demo_control.ValueVisible = true;
            this.demo_control.WaveSize = new Size(30,10);
            this.demo_control.WaveVelocity = 5;

            this.appearance_dropDownListPlus.Multiple = false;
            this.appearance_dropDownListPlus.BindEnumList<WaterRipplesStylePattern>(this.demo_control.StylePattern);
            this.appearance_dropDownListPlus.SelectedItemsChanged += this.StylePattern_dropDownListPlus_SelectedItemsChanged;

            this.valueVisible_toggleSwitch.IsOn = this.demo_control.ValueVisible;
            this.valueVisible_toggleSwitch.Toggled += this.ValueVisible_toggleSwitch_Toggled;

            this.borderThickness_label.Text = this.demo_control.BorderThickness.ToString();
            this.borderThickness_trackBarPlus.Value = this.demo_control.BorderThickness;
            this.borderThickness_trackBarPlus.ValueChanged += this.BorderThickness_trackBarPlus_ValueChanged;

            this.value_label.Text = this.demo_control.Value.ToString();
            this.value_trackBarPlus.Value = (float)this.demo_control.Value;
            this.value_trackBarPlus.ValueChanged += this.Value_trackBarPlus_ValueChanged;

            this.label21.Text = this.demo_control.WaveSize.Height.ToString();
            this.waveHeight_trackBarPlus.Value = (float)this.demo_control.WaveSize.Height;
            this.waveHeight_trackBarPlus.ValueChanged += this.WaveHeight_trackBarPlus_ValueChanged;

            this.waveWidth_label.Text = this.demo_control.WaveSize.Width.ToString();
            this.waveWidth_trackBarPlus.Value = (float)this.demo_control.WaveSize.Width;
            this.waveWidth_trackBarPlus.ValueChanged += this.WaveWidth_trackBarPlus_ValueChanged;

            this.waveVelocity_label.Text = this.demo_control.WaveVelocity.ToString();
            this.waveVelocity_trackBarPlus.Value = (float)this.demo_control.WaveVelocity;
            this.waveVelocity_trackBarPlus.ValueChanged += this.WaveVelocity_trackBarPlus_ValueChanged;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void StylePattern_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.StylePattern = (WaterRipplesStylePattern)control.SelectedItem.Tag;
        }

        private void BorderThickness_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.BorderThickness = (int)control.Value;
            this.borderThickness_label.Text = this.demo_control.BorderThickness.ToString();
        }

        private void Value_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Value = control.Value;
            this.value_label.Text = this.demo_control.Value.ToString();
        }

        private void ValueVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ValueVisible = control.IsOn;
        }
       
        private void WaveHeight_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.WaveSize =new Size(this.demo_control.WaveSize.Width, (int)control.Value);
            this.label21.Text = this.demo_control.WaveSize.Height.ToString();
        }

        private void WaveWidth_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.WaveSize = new Size( (int)control.Value,this.demo_control.WaveSize.Height);
            this.waveWidth_label.Text = this.demo_control.WaveSize.Width.ToString();
        }

        private void WaveVelocity_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.WaveVelocity = (int)control.Value;
            this.waveVelocity_label.Text = this.demo_control.WaveVelocity.ToString();
        }

        #endregion

    }
}
